package com.example.osixaffairssystem.service.impl;

import com.example.osixaffairssystem.domain.PageBean;
import com.example.osixaffairssystem.domain.model.Dept;
import com.example.osixaffairssystem.mapper.DeptMapper;
import com.example.osixaffairssystem.service.DeptService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


@Service
@RequiredArgsConstructor
public class DeptServiceImpl implements DeptService {

    final DeptMapper deptMapper;

    @Override
    public List<Dept> list() {
        return deptMapper.list();
    }

    @Override
    public PageBean<Dept> listToPage(@RequestParam(name = "page") Integer page,
                                     @RequestParam(name = "pageSize") Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        Page<Dept> p = (Page<Dept>) deptMapper.list();

        return new PageBean<>(p.getTotal(), p.getResult());
    }

    @Override
    public Integer insert(Dept dept) {
        deptMapper.insert(dept);
        return dept.getId();
    }

    @Override
    public void update(Dept dept) {
        deptMapper.update(dept);
    }

    @Override
    public void delete(List<Integer> ids) {
        deptMapper.delete(ids);
    }
}
